package se.ramfelt.psnfriends;

import com.google.android.divideandconquer.Eula;

import se.ramfelt.psnfriends.util.RandomXorObfuscator;
import android.content.Context;
import android.preference.EditTextPreference;
import android.util.AttributeSet;

/**
 * Obfuscates a edit text when it is persisted to file
 */
public class ObfuscatedEditTextPreference extends EditTextPreference {

	private RandomXorObfuscator obfuscator;
	
	public ObfuscatedEditTextPreference(Context context) {
		super(context);
		obfuscator = new RandomXorObfuscator(Eula.getAcceptedTime(context));
	}

	public ObfuscatedEditTextPreference(Context context, AttributeSet attrs,
			int defStyle) {
		super(context, attrs, defStyle);
		obfuscator = new RandomXorObfuscator(Eula.getAcceptedTime(context));
	}

	public ObfuscatedEditTextPreference(Context context, AttributeSet attrs) {
		super(context, attrs);
		obfuscator = new RandomXorObfuscator(Eula.getAcceptedTime(context));
	}

	@Override
	protected String getPersistedString(String defaultReturnValue) {
		return obfuscator.reverse(super.getPersistedString(defaultReturnValue));
	}

	@Override
	protected boolean persistString(String value) {
		return super.persistString(obfuscator.perform(value));
	}	
}
